package math
// 除法运算
import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"

//divide double
type DDIV struct{
	base.NoOperandsInstruction
}

func(self *DDIV)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopDouble()
	v1 := stack.PopDouble()
	result := v1 /v2
	stack.PushDouble(result)
}

//divide float
type FDIV struct{
	base.NoOperandsInstruction
}

func (self *FDIV)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopFloat()
	v1 := stack.PopFloat()
	result := v1 / v2
	stack.PushFloat(result)
}
//devie int
type IDIV struct {
	base.NoOperandsInstruction
} 

func (self *IDIV)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopInt()
	v1 := stack.PopInt()
	if v2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	result := v1 / v2
	stack.PushInt(result)
}

//divie long
type LDIV struct{
	base.NoOperandsInstruction
}
func(self *LDIV)Execute(frame *rtda.Frame){
	stack := frame.OperandStack()
	v2 := stack.PopLong()
	v1 := stack.PopLong()
	if v2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	result := v1 / v2
	stack.PushLong(result)
}


